﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMIS.Enums;
using DX.CRC.Common.WebUtil;
using SMIS.Dals;
using SMIS.Entities;

namespace SMIS
{
    public partial class ModifyStaff : Form
    {
        public int MdfID { get; set; }
        public string MdfName { get; set; }
        public string MdfSex { get; set; }
        public string MdfJobName { get; set; }
        public string MdfDepName { get; set; }
        public string MdfPosition { get; set; }
        public string MdfMajor { get; set; }
        public string MdfEduBgd { get; set; }
        public string MdfPlace { get; set; }
        public DateTime MdfBirthday { get; set; }
        public DateTime MdfStartWorkingDate { get; set; }
        public DateTime MdfDatesEmployed { get; set; }
        public string MdfRemark { get; set; }

        public Sex Sex { get { return CommonUtility.Convert2Enum(MdfSex, Sex.Unknown); } }
        public EducationBgd EducationBackground { get { return CommonUtility.Convert2Enum(MdfEduBgd, EducationBgd.Unknown); } }

        public ModifyStaff()
        {
            InitializeComponent();
        }

        private void ModifyStaff_Load(object sender, EventArgs e)
        {
            //int SID = MdfID;
            txtName.Text = MdfName;
            cboSex.Text = MdfSex;
            //cboJob.Text = MdfJobName;
            //cboDepart.Text = MdfDepName;
            txtPosition.Text = MdfPosition;
            txtMajor.Text = MdfMajor;
            cboEduBgd.Text = MdfEduBgd;
            txtPlace.Text = MdfPlace;
            dateTimePicker1.Value = MdfBirthday;
            dateTimePicker2.Value = MdfStartWorkingDate;
            dateTimePicker3.Value = MdfDatesEmployed;
            txtRemark.Text = MdfRemark;

            //性别
            cboSex.Items.Add(Sex.Male);
            cboSex.Items.Add(Sex.Female);
            //cboSex.SelectedIndex = 0;

            //学历
            cboEduBgd.Items.Add(EducationBgd.Bachlor);
            cboEduBgd.Items.Add(EducationBgd.Master);
            cboEduBgd.Items.Add(EducationBgd.Doctor);
            //cboEduBgd.SelectedIndex = 0;

            //工种
            CommonUtil.BindData4ComboBox(cboJob, Dal4Staff.GetJobs(), "JobName", "JobID");
            cboJob.Text = MdfJobName;
                

            //部门
            CommonUtil.BindData4ComboBox(cboDepart, Dal4Staff.GetDeparts(), "DName", "DID");
            cboDepart.Text = MdfDepName;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Staff staff = new Staff();
            staff.SID = MdfID;
            staff.SName = txtName.Text;
            staff.Sex_Field = cboSex.Text;
            staff.JobName = cboJob.Text;
            staff.DepName = cboDepart.Text;
            staff.Position = txtPosition.Text;
            staff.Major = txtMajor.Text;
            staff.EducationBackground_Field = cboEduBgd.Text;
            staff.Place = txtPlace.Text;
            staff.Birthday = dateTimePicker1.Value;
            staff.StartWorkingDate = dateTimePicker2.Value;
            staff.DatesEmployed = dateTimePicker3.Value;
            staff.Remark = txtRemark.Text;

            Dal4Staff.UpdateSelectedStaff(staff);
            MessageBox.Show("恭喜你修改员工信息成功！", "提示");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
